import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * @author: gao
 * @create-date: 2025/4/4 21:47
 */

public class Solution {
    public int[] inventoryManagement(int[] stock, int cnt){
        Quicksort(stock,0,stock.length - 1,cnt);
        int[] ret = new int[cnt];
        for (int i = 0; i < cnt; i++) {
            ret[i] = stock[i];
        }
        return ret;
    }

    private void Quicksort(int[] nums, int l, int r, int k) {
        if(l >= r) return;

        //随机获取基准元素
        int key = nums[new Random().nextInt(r - l + 1) + l];
        int left = l - 1,right = r + 1,i = l;

        //数组分三块
        while(i < right){
            if(nums[i] < key) swap(nums,++left,i++);
            else if (nums[i] == key) i++;
            else if (nums[i] > key) swap(nums,--right,i);
        }

        //分类讨论
        int a = left - l + 1,b = right - left - 1;
        if(a > k) Quicksort(nums,l,left,k);
        else if (a + b >= k) return;
        else Quicksort(nums,right,r,k - a - b);
    }

    private void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int len = in.nextInt();
            int[] nums = new int[len];
            for (int i = 0; i < len; i++) {
                nums[i] = in.nextInt();
            }
            int k = in.nextInt();
            Solution solution = new Solution();
            System.out.println(Arrays.toString(solution.inventoryManagement(nums,k)));
        }
    }
}